<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>使用matchAll完成全局匹配</title>
  </head>
  <body>
    <h1>houdunren.com</h1>
    <h2>hdcms.com</h2>
    <h1>baidu.com</h1>
  </body>
  <script>
    const body = document.body;

    let reg = /<(h[1-6])>([\s\S]+?)<\/\1>/gi;
    //matchAll()返回一个迭代器
    const hd = body.innerHTML.matchAll(reg);

    const contents = [];
    for (const iterator of hd) {
      contents.push(iterator[2]);
    }
    console.table(contents);
  </script>
</html>
